<template>
  <div class="login" v-loading="loading" element-loading-background="rgba(122, 122, 122, 0.8)">
    <el-card class="card">
      <template #header>
        <div class="card-header">
          <span>登录 Dlg系统</span>
        </div>
      </template>
      <el-form :model="loginForm" :rules="rules" label-width="auto">
        <el-form-item label="用户名" prop="name">
          <el-input v-model="loginForm.name" clearable />
        </el-form-item>
        <el-form-item label="密码" password>
          <el-input v-model="loginForm.password" show-password />
        </el-form-item>
        <div class="go-index">
          <el-button class="login-btn" type="primary" @click="handleLogin">登录</el-button>
        </div>
      </el-form>
    </el-card>
  </div>
</template>
<script setup lang="ts">
import { onMounted, reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
import { setToken } from '@/utils/auth'
const router = useRouter()
const loading = ref(false)
const loginForm = reactive<{
  name: string;
  password: string
}>({
  name: 'dlg',
  password: '123456F'
})
const rules = reactive({
  name: [
    { required: true, message: '请输入用户名', trigger: 'blur' },
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'blur' },
  ],
})
const handleLogin = async () => {
  loading.value = true
  setToken('123456')
  await setTimeout(() => {
    loading.value = false
    router.push({
      path: '/index',
      replace: true
    })
  }, 2000);
}
</script>

<style lang="scss" scoped>
.login {
  width: 100vw;
  height: 100vh;
  background-image: url('@assets/image/login.png');
  background-size: 100% 100%;
  position: relative;

  .card {
    width: 500px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);

    .go-index {
      display: flex;
      justify-content: center;

      .login-btn {
        width: 450px;
        margin: 0 auto;
      }
    }
  }
}
</style>
